<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>

     <script type="text/javascript" src="${basePath}/js/jquery.Huploadify.js"></script>
     <link href="${basePath}/css/Huploadify.css" rel="stylesheet">
<style>

table label.error {
    margin-left: 5px;
    width: auto;
    display: inline;
    color: red;
}
</style>

<script type="text/javascript">

$(document).ready(
					function() {
						$("#div1").dialog({
							width : 'auto',
							height : 'auto',
							bgiframe : true,
							modal : true,
							draggable : true,
							resizable : false,
							title : '选择负责人',
							autoOpen : false,
						    buttons : {
						    '取消' : function() {
						    	$(this).dialog('close');
							},
							'确定' : function() {
								  if($("#fromSelect").val()==null||$("#fromSelect").val()==""){
									  layer.alert("请选择一项", {icon: 6});
									 return false;
								  }
							 
								    var formSelect = document.getElementById("fromSelect");
								    var str = [];
								    var num=0;
								    for(i=0;i<formSelect.length;i++){
								        if(formSelect.options[i].selected){
								            num++;
								        }
								    }
								    if(num>=2){
								      layer.alert("只能选择一项", {icon: 6});
								      return false;
								    }
							  
							  $("#xm").val($("#fromSelect").find("option:selected").text());
							  $("#projectMaterialPrincipal").val($("#fromSelect").val());
							  $(this).dialog('close');
							  
							}
						  }
						});
						
						

					

					});
	function showdiv() {
		  $("#xm").val("");
		  $("#projectMaterialPrincipal").val("");
		  $("#searchemp").val(""); 
		$('#div1').dialog('open');
	}
</script>

</script>

<script type="text/javascript">
//图片上传
var file_path = "prefix";
var file_path_one = null;
var fileMap = new Array();
$(function(){
		var up = $('#uploadadd').Huploadify({
			auto:false,
			fileTypeExts:'*.*',
			multi:true,
			formData:{key:123456,key2:'vvvv'},
			fileSizeLimit:99999999999,
			showUploadedPercent:true,
			showUploadedSize:true,
			removeTimeout:9999999,
			uploader : '${basePath}/projectmaterial/source_upload',
			onUploadStart:function(file){
				console.log(file.name+'开始上传');
			},
			onInit:function(obj){
				console.log('初始化');
			},
			onUploadComplete:function(file,data){
				
				    var fi = $.parseJSON(data);
				    //文件名称
				    var filename = fi.filename;
				    //生成后的文件名
				    var sysFilepath = fi.sysfilepath;
				    //文件路径
				    var filepath = fi.filepath;
				    file_path_one = filename + "," + filepath;
				    file_path = file_path+"|"+filepath;
				    up.filePath=file_path_one;
				    //保存到集合
	                fileMap[file.index]=new Array(file_path_one);
			},
			onCancel:function(file){
				console.log(file.name+'删除成功');
			},
			onClearQueue:function(queueItemCount){
				console.log('有'+queueItemCount+'个文件被删除了');
			},
			onDestroy:function(){
				console.log('destroyed!');
			},
			onSelect:function(file){
				console.log(file.name+'加入上传队列');
			},
			onQueueComplete:function(queueData){
				console.log('队列中的文件全部上传完成',queueData);
			}
		  });	
});

   
//删除图片 
 function deletefile(id){
     	var url = "${basePath}/projectmaterial/deletefile";
		$.ajax({
			type : "POST",
			url : url,
			dataType:"json",
			data:{
				filepath : id
			},
			success : function(data) {
				if(data.success == "0000"){
					layer.alert('删除数据成功', {icon: 6});
					var file_name = id.split(",")[0];
					
					$("#"+file_name+"_hr").parent().parent().remove();
				}else{
					alert("未写入数据库的文件没有删除！请联系管理员！");
				}
			}
		})
   } 
</script>	
</head>
<body>
     <form action="#" name="Form" id="Form" method="post">
       <input type="hidden" name="directoryId" id="directoryId"  value="${directoryId}"/> 
       <input type="hidden" name="projectId" id="projectId"  value="${projectId}"/> 
       <input type="hidden" name="level" id="level"  value="${level}"/> 
       
		<table cellpadding="0" cellspacing="0" border="0" class="table-border" width="80%">
			<tr>
				<td class="table-header" colspan="4">材料管理</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>目录名称：</td>
				    <c:forEach items="${Listdata}" var="i">
				     	<td class="table-contentTD" style="width: 70%">${i.directoryName}
				   	    <input type="hidden" name="directoryId" id="directoryId"  value="${i.directoryId}"/> 
				   	   </td>
			        </c:forEach>
			<%-- 	<select id ="directoryId" name="directoryId"  class ="selectList required "  disabled="disabled"   style="width: 50%" >
				        <c:forEach items="${Listdata}" var="i">
							 <option value="${i.directoryId}">${i.directoryName}</option>
					    </c:forEach>
				</select> --%>
			</tr>
			
			<tr>
				<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>主题：</td>
				<td class="table-contentTD" style="width: 70%">
				<input type="text" id="title" name="title"  placeholder="主题"  autocomplete="off"  maxlength="100" class="inputText required" /></td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width: 30%"><font
					style="color: red;">*</font>时间：</td>
				<td class="table-contentTD" style="width: 70%">
		     	<input name="date1" id="date1" placeholder="时间"   autocomplete="off" 
									class="Wdate required text inputText2" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"/></td>
			</tr>
			
           <tr>
			    <td class="table-titleTD" style="width: 30%">负责人：</td>
					<td class="table-contentTD" style="width: 70%">
			    <input type="hidden" name="projectMaterialPrincipal" id="projectMaterialPrincipal"/>
				<input type="text" id="xm" name="xm"  readonly="readonly"  class="inputText" style="width: 62%" />
				<input type="button" id="optionBtn" value="选择" class="inputButton" 
					onclick="javascript:showdiv();" /><font style="color: red;">&nbsp;&nbsp;&nbsp;&nbsp;*注: 负责人不选择默认材料负责人是当前登入人。</font></td>	
			</tr> 
			<tr>
			     <td class="table-titleTD"><font style="color: red;">*</font>文件上交类型：</td>
				 <td class="table-contentTD"> 
					  <input type="radio" value="1"  name="projectMaterial_type"   onclick="checkedOK()"  checked="checked" />上交
					  <input type="radio" value="2"  name="projectMaterial_type"   onclick="checkedOK()" />个人
			    </td>
			</tr>
			
			<tr>
			  <td class="table-titleTD" style="width: 30%">附件：</td>
							 <td colspan="3">
								   <div id="uploadadd"></div>
							 </td>
			</tr>
			
			<tr>
				<td class="table-titleTD">备注：</td>
				<td class="table-contentTD" colspan="3" style="width: 100%"><textarea style="width: 90%;height: 80px;" name="remark"  placeholder="备注" id="remark" maxlength="2000" ></textarea></td>
			</tr>
		</table>
		<br />
		<table cellpadding="1" cellspacing="1" border="0" align="left">
			<tr>
				 <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId(\"OF_ZLTS_CLGL\")%>" key="add">
			    <td><input type="button" id="btnSave" class="inputButton"
					style="text-align: center;" value="保存" /></td>
				<td><input type="button" id="btnSaveContinue" class="inputButton"
					style="text-align: center;" value="保存并新增" /></td>
					</kl:permission>
				<td><input type="button" id="Cancel" class="inputButton"
					style="text-align: center;" value="取消" /></td>
				<td><input type="button" id="returnBut" class="inputButton"
					value="返回" style="text-align: center;" /></td>
			</tr>
		</table>
		
		
		 <div id="div1" style="display: none;">
			<table cellpadding="0" cellspacing="0" border="0" class="table-border">
				  <tr>
				  	 <td style="clear:both; width: 70%">
				  	  <input class="text" id="searchemp" name="searchemp" ondblclick="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"  onkeyup="javascript:filterSelectItems('sourseFromSelect2','fromSelect','fromSelect',this.value);"/><font color="green">在此查找</font> <br/>
				  	   <br/><label style="color:red;">未选中:</label><br/>
				  	   <select name="fromSelect" id="fromSelect" multiple="multiple"  size="1"  multiple="false" style="width:200px; height: 250px;"
							ondblclick="moveField('fromSelect','toSelect');">
											<%-- <c:forEach items="${List}" var="data">
									       <option value="${data.emid}">${data.xm}</option>
								          </c:forEach> --%>
						</select>
							<select name="sourseFromSelect2" id="sourseFromSelect2"   multiple="false" style="width: 220px; height: 150px; display: none;" >
										<%--   <c:forEach items="${List}" var="data">
									       <option value="${data.emid}">${data.xm}</option>
								          </c:forEach> --%>
  	    </select>
						
					 </td>
  	              </tr>
			</table>
		</div>
		
		<script>
		
			$(document).ready(function() {
				var _form=$("#Form").validate();
				$("#btnSave").click(function() {
					if(_form.form()){
						/*  validateObj(); */
						    document.Form.action ="${basePath}/projectmaterial/add";
							document.Form.submit();
					 }
				});
				
				$("#btnSaveContinue").click(function() {
					if(_form.form()){
						document.Form.action ="${basePath}/projectmaterial/addSaveContinue";
						document.Form.submit();
					}
				});
				$("#Cancel").click(function() {
					 window.location.href = "${basePath}/projectmaterial/addInInt?directoryId="+${directoryId}+"&projectId="+${projectId}+"&level="+${level};
					// window.location.href='${basePath}/projectmaterial/index';
		 		});
				
				$("#returnBut").click(function() {
		 			 window.location.href="${basePath}/projectmaterial/index?directoryId="+${directoryId}+"&projectId="+${projectId}+"&level="+${level-1};
		 			/*  window.location.href='${basePath}/projectmaterial/index?directoryId='+${directoryId}; */
					 //window.location.href='${basePath}/projectmaterial/index' 
		 		});
				
				 if("${msg}"!=""){
				       layer.alert("${msg}", {icon: 6});
				 } 
				 
				 
				  $("#fromSelect").empty(); 
				  $("#sourseFromSelect2").empty(); 
				  $("#searchemp").val(""); 
				  var val = $('input:radio[name="projectMaterial_type"]:checked').val();
				  $.ajax({
					  type: 'POST',
					  url: "${basePath}/projectmaterial/selectclfzr",
				      data:{projectId: $('#projectId').val(),directoryId:$('#directoryId').val(),level:$('#level').val(),logo:val},
					  success:function(data){
						   var json = typeof data=='string'?JSON.parse(data) :data;
						   if(json.msg=="100"){
							   $.each(json.list, function(i, item) {
								  $("#fromSelect").append("<option  value='" + item.emid + "'>"+ item.xm+ "</option>");
								  $("#sourseFromSelect2").append("<option  value='" + item.emid + "'>"+ item.xm+ "</option>");
							  });
						   }else if(json.msg=="-100"){
							  
						   }
					  } 
				    });	
				
				
			});
			
			function checkedOK() {
				  $("#xm").val("");
				  $("#projectMaterialPrincipal").val("");
				  $("#searchemp").val(""); 
				  var val = $('input:radio[name="projectMaterial_type"]:checked').val();
					  $.ajax({
						  type: 'POST',
						  url: "${basePath}/projectmaterial/selectclfzr",
					      data:{projectId: $('#projectId').val(),directoryId:$('#directoryId').val(),level:$('#level').val(),logo:val},
						  success:function(data){
							   var json = typeof data=='string'?JSON.parse(data) :data;
							   if(json.msg=="100"){
								   $("#fromSelect").empty(); 
								   $("#sourseFromSelect2").empty(); 
								   $("#searchemp").val(""); 
								   $.each(json.list, function(i, item) {
									  $("#fromSelect").append("<option  value='" + item.emid + "'>"+ item.xm+ "</option>");
									  $("#sourseFromSelect2").append("<option  value='" + item.emid + "'>"+ item.xm+ "</option>");
								  });
							   }else if(json.msg=="-100"){
							   }
						  } 
					    });	
			 }
		</script>
	</form>
</body>
</html>
